using System.Collections;

namespace Myotragus.Data.Criteria
{
	public class WriteQueryBuilder : ReadQueryBuilder, IWriteQueryBuilder
	{
		public WriteQueryBuilder(ISessionFactoryAdapter sessionFactory)
			: base(sessionFactory)
		{
		}

		public void Save(IEnumerable entities)
		{
			var session = OpenSession();

			foreach (var entity in entities)
				using (var transaction = session.BeginTransaction())
				{
					session.Save(entity);
					transaction.Commit();
				}

			session.Flush();
		}

		public void Delete(IEnumerable entities)
		{
			var session = OpenSession();

			foreach (var entity in entities)
				using (var transaction = session.BeginTransaction())
				{
					session.Delete(entity);
					transaction.Commit();
				}

			session.Flush();
		}
	}
}